﻿using System;
using System.Text;
using System.Text.RegularExpressions;

namespace UDS
{
    public static class Transforms
    {
        /// <summary>
        /// Helper function used to ensure we don't inject script into the db.
        /// </summary>
        /// <param name="dirtyText">Text to be cleaned for script tags</param>
        public static string StripScriptTags(string dirtyText)
        {
            if (string.IsNullOrEmpty(dirtyText))
            {
                string cleanText;

                // Perform RegEx
                dirtyText = Regex.Replace(dirtyText, "<script((.|\n)*?)</script>", "", RegexOptions.IgnoreCase | RegexOptions.Multiline);
                cleanText = Regex.Replace(dirtyText, "\"javascript:", "", RegexOptions.IgnoreCase | RegexOptions.Multiline);

                return cleanText;
            }

            return dirtyText;
        }

        public static string StripHtmlXmlTags(string content)
        {
            return Regex.Replace(content, "<[^>]+>", "", RegexOptions.IgnoreCase);
        }
    }
}
